<template>
	<om-formsub-outer :index="index">
		<om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	import {buildSubFormData,subOnLoad, changeEditor,configSelectData} from '../../../static/js/formUtil.js';
	import { ignoreHtml,ptFloat,minusF,getDateStr} from '@/static/js/common.js';
	import urlUtil from '@/static/js/urlUtil.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				initValue:{
					userId:"",
					userName:"",
					postId:"",
					postName:"",
				},
				userPosCache:"mkt-customer-requirement-data-info-title5-userposcache"
			})
		},
		methods: {
			initLoad(){
				let _that = this
				changeEditor('title5', 'userPostId', {
					link: "../../public/pageSearch/pageSearch",
					linkParam: {
						namefield:urlUtil.officePageUrl().namefield,
						searchfield:"q",
						url:urlUtil.officePageUrl().url,
						cachename:_that.userPosCache,
						placeholder:urlUtil.officePageUrl().prompt
					}
				},null,_that.autoformdata);
			}
		},
		onLoad(e){
			let _that = this
			subOnLoad(_that, e, function() {
				if(e.configDataCacheKey){
					uni.getStorage({
						key: e.configDataCacheKey,
						success: function(res) {
							//if(res.data && res.data instanceof Array){
							if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
								_that.autoformdata = res.data
								Object.assign(_that.initValue, _that.formdata)
								_that.autoformdata[0].order = _that.order
								_that.initLoad()
							}
						}
					});
				}
			})
		},
		onShow() {
			let _that = this;
			if (_that.$refs.autoform) {
				uni.getStorage({
					key: _that.userPosCache,
					success: function(res) {
						if(res.data){
							let rowData = res.data
							var row  = _that.$refs.autoform.formdata
							row.userPostId = rowData.id;
							row.userId = rowData.userId;
							row.userName = rowData.userName;
							row.postId = rowData.posId;
							row.postName = rowData.posInstName;
							row.instId = rowData.instId;
							row.instName = rowData.instName;
							uni.removeStorage({
								key: _that.userPosCache
							});
						}
					}
				});
			}
		}
	}
</script>
